from sqlalchemy import create_engine
from SpiffGuard import *

class Passenger(Resource):
    pass

class Room(Resource):
    pass

db    = create_engine('mysql://tester:test@localhost/unit_tests')
guard = DB(db)
guard.install()
guard.register_type([Passenger, Room, Action])

han    = Passenger("Han Solo")
luke   = Passenger("Luke Skywalker")
bridge = Room("Bridge")
mr     = Room("Machine Room")
guard.add_resource(None, [han, luke, bridge, mr])

enter  = Action("Enter")
repair = Action("Repair")
guard.add_action(enter)
guard.add_action(repair)

guard.grant(han, [enter, repair], mr)
guard.grant(luke, enter, [mr, bridge])

if guard.has_permission(han, enter, mr):
    print "Permission was granted."
else:
    print "Permission was denied."
